package com.example.service.impl;

import com.example.dao.CodeGenerationMapper;
import com.example.service.CodeGenerationService;
import javafx.scene.Parent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Slf4j
@Service
public class CodeGenerationServiceImpl implements CodeGenerationService {

    @Value("${spring.datasource.url:}")
    private String dataBaseUrl;
    @Autowired
    private CodeGenerationMapper codeGenerationMapper;
    @Override
    public List<String> getAllTableName() {
        log.info(dataBaseUrl);
        String dataBaseName = "";
        //jdbc:mysql://10.20.50.207:3306/materials?useUnicode=true&useJDBC....
        String regex = "/(\\w+)\\?";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(dataBaseUrl);
        if(m.find()){
            dataBaseName = m.group(0);
            //  dataBaseName====  /materials?
            dataBaseName= dataBaseName.replace("/","");
            dataBaseName =dataBaseName.replace("?","");
        }else{
            log.info("no match!!!!");
        }
        List<String> list = codeGenerationMapper.getAllTableName(dataBaseName);
        return list;
    }
}
